'''
作业
'''


# 1.
def sum1(n: int) -> int:
    """
    求1+2+3+…n的和
    :param n:int
    :return:int
    """
    s = 0
    for i in range(1, n + 1):
        s += i
    return s


# 2.
def max1(list1: list) -> int:
    m = max(list1)
    return m


# 3.
def sum2(list1: list) -> int:
    s = sum(list1)
    return s


# 4.
def exchange_dict(dic: dict) -> dict:
    """
    交换字典dic1 = {1: 'a', 2: 'b', 3: 'c'}的key和value
    :return:
    """
    dic2 = {}
    for key in dic:
        dic2[dic[key]] = key
    return dic2


# 5.
def new_s(s: str) -> str:
    """
    提取指定字符串中所有的字母，然后拼接产生一个新的字符串
    :param s:
    :return:
    """
    s1 = ''
    for i in s:
        if 'a' <= i <= 'z' or 'A' <= i <= 'Z':
            s1 += i
    return s1


# 6.
def avg(*args) -> float:
    """
    求多个数的平均值
    :param args:
    :return:
    """
    a = sum(args) / len(args)
    return a


# 7.
def func1(num=4) -> int:
    """
    求4的阶乘
    :param num:
    :return:
    """
    s = 1
    for i in range(1, num + 1):
        s *= i
    return s


# 8.
def cap(s: str) -> str:
    """
    将指定字符串的首字母变成大写字母
    :param s:
    :return:
    """
    if 'a' <= s[0] <= 'z':
        s0 = chr(ord(s[0]) - ord('a') + ord('A'))
        s = s0 + s[1:]
    return s


# 9.
def end_s(s1: str, s2: str) -> bool:
    """
    判断一个字符串1是否是指定字符串2结尾
    :param s1:
    :param s2:
    :return:
    """
    if s1[len(s1) - len(s2):] == s2:
        return True
    else:
        return False


# 10
def is_d(s: str) -> bool:
    """
    判断一个字符串是否是纯数字字符串
    :param s:
    :return:
    """
    for i in s:
        if not ('0' <= i <= '9'):
            return False
    else:
        return True


# 11
def up(s: str) -> str:
    """
    将一个字符串中的所有小写字母变成大写
    :param s:
    :return:
    """
    s1 = ''
    for i in s:
        if 'a' <= i <= 'z':
            x = chr(ord(i) - 97 + 65)  # 用小字母编码值与a编码值的差，加上A编码值
            s1 += x
        else:
            s1 += i
    return s1


# 12
def r_just(s1: str, s2: str, num: int) -> str:
    """
    将一个字符串在一个指定长度的新字符串中右对齐，剩下部分用指定字符填充
    :param s1:
    :param num:
    :param s2:
    :return:
    """
    s1_len = len(s1)
    if num > s1_len:
        s2 = s2 * (num-s1_len)
        print('s2:',s2)
        s1 = s2 + s1
    return s1


# 13
def _index(lis: list, s: str) -> int:
    """
    查找指定元素在指定列表中的所有下标，没有指定元素则返回-1
    :param lis:
    :param args:
    :param s:
    :return:
    """
    for index,value in enumerate(lis):
        if s == value:
            return index
    else:
        return -1



# 14
def _len(seq:iter, s:str) -> int:
    """
    统计指定序列中元素个数
    :param args:
    :param kwargs:
    :return:
    """
    count = 0
    for i in seq:
        if i == s:
            count += 1
    return count


# 15
def _max(seq:iter, s) -> str:
    """
    获取序列中元素的最大值
    :param args:
    :param kwargs:
    :return:
    """
    max_s = seq[0]
    if type(seq) == 'dict':
        for key in seq:
            if seq[key] > max_s:
                max_s = seq[key]
    else:
        for i in seq:
            if i > max_s:
                max_s = i
    return max_s


# 16
def _in(seq: iter, s: str) -> bool:
    """
    判断序列中是否存在指定元素
    :param args:
    :param s:
    :return:
    """
    for i in seq:
        if s == i:
            return True

    else:
        return False


# 17
def _repalece(s: str, old_str: str, new_str: str) -> str:
    """
    将字符串中的指定的旧字符串转换成指定的新字符串
    :param s:
    :param old_str:
    :param new_str:
    :return:
    """
    s = ''
    return s


# 18
def _intersection(list1: list, list2: list) -> list:
    """
    求两个列表的交集
    :param list1:
    :param list2:
    :return:
    """
    list3 = []
    for i in list1:
        if i in list2:
            list3.append(i)
    return list3


def _union(list1: list, list2: list) -> list:
    """
    求两个列表的并集
    :param list1:
    :param list2:
    :return:
    """
    list3 = list(set(list1 + list2))
    return list3


def _difference(list1: list, list2: list) -> list:
    """
    求两个列表的差集
    :param list1:
    :param list2:
    :return:
    """
    list3 = []
    for i in list1:
        if i not in list2:
            list3.append(i)
    return list3


def _supplementary(list1: list, list2: list) -> list:
    """
    求两个列表的补集
    :param list1:
    :param list2:
    :return:
    """
    list3 = []
    for i in list1:
        if i not in list2:
            list3.append(i)
    for i in list2:
        if i not in list1:
            list3.append(i)
    return list3
